package com.bw.lyc.mvp.model;

import com.bw.lyc.mvp.base.model.BaseEntity;
import com.bw.lyc.mvp.base.model.BaseModel;
import com.bw.lyc.mvp.contract.UpdateUserContract;
import com.bw.lyc.mvp.model.entity.UploadEntity;
import com.bw.lyc.network.Api;
import com.bw.lyc.network.ChangeFunction;
import com.bw.lyc.network.http.HttpFactory;
import com.bw.lyc.network.http.HttpType;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import io.reactivex.Observable;
import okhttp3.MultipartBody;

public class UpdateUserModel extends BaseModel implements UpdateUserContract.IUpdateUserModel {
    @Inject
    public UpdateUserModel(){}
    @Override
    public Observable<BaseEntity> request(Map<String, Object> map) {
        int  code = (int) map.get("code");
        List<MultipartBody.Part> list = (List<MultipartBody.Part>) map.get("list");
        map.remove("list");
        map.remove("code");
        if (code== HttpCode.UPDATEUSERCODE){
            Observable<BaseEntity> ob = HttpFactory.getInstance().factory(HttpType.TOKENSIGNTYPE).getRetrofit()
                    .create(Api.class).requestUpdateUser(createBody(map));
            return ob.map(new ChangeFunction<BaseEntity>());
        }else if (code==HttpCode.UPLOADIMGCODE){
            Observable<UploadEntity> ob = HttpFactory.getInstance().factory(HttpType.UPLOADTYPE)
                    .getRetrofit().create(Api.class)
                    .requestUploadHead(list);
            return ob.map(new ChangeFunction<UploadEntity>());
        }

        return null;
    }
}
